package com.manger.common.tcp.decode.impl;

import com.manger.common.tcp.constant.TcpDataType;
import com.manger.common.tcp.decode.BaseDecode;
import com.manger.common.utils.SocketByteConvertUtils;

public class BusinessDecode extends BaseDecode {

    private String content;

    public BusinessDecode(TcpDataType tcpDataType) {
        this.setTcpDataType(tcpDataType);
    }

    public BusinessDecode(int code) {
        this.setTcpDataType(TcpDataType.getTcpDataType(code));
    }

    @Override
    public void decode(byte[] data) {
        int len = SocketByteConvertUtils.bigEndian4ByteToInt(SocketByteConvertUtils.midByteArray(data,3,4));
        byte[] contentBytes = SocketByteConvertUtils.midByteArray(data,7,data.length - 7);
        content = new String(contentBytes);
    }

    public String getContent() {
        return content;
    }
}
